

#ifndef __EV_BASE_H__
#define __EV_BASE_H__

#include <atomic>
#include <stdint.h>
#include <event2/event.h>

class EvBase {

public:
    static EvBase* getInstance();

public:
    int run();
    int exit(uint32_t ms);
    uint32_t run_time();
    event_base *get_base() const;
    bool is_ready() const;

private:
    EvBase();
    ~EvBase();
    EvBase(const EvBase&) = delete;
    EvBase& operator=(const EvBase&) = delete;
    EvBase& operator=(EvBase&& other) = delete;

private:
    struct event_base *base_;
    struct event *timer_;
    std::atomic<uint32_t> run_time_;

private:
    static void timer_cb(evutil_socket_t fd, short event, void *arg);
};

#endif
